﻿using FluentValidation;
using PMS.Data.DbUtils;
using PMS.Data.Entities.Messages;
using PMS.Web.Framework.Validators;
using PMS.Web.Models.Messages;

namespace PMS.Web.Validators.Customer
{
    public partial class QueuedEmailValidator : BaseModelValidator<QueuedEmailModel>
    {
        public QueuedEmailValidator(IDbContext dbContext)
        {
            RuleFor(m => m.To).NotEmpty().WithMessage(ValidatorRuleString.EmailRequired);
            //Validate Email when email info not hide like a****@example.com
            RuleFor(x => x.To).EmailAddress().When(x => !x.To.Contains('*')).WithMessage(ValidatorRuleString.Validators_Email);
            RuleFor(m => m.ToName).NotEmpty().WithMessage(string.Format(ValidatorRuleString.FieldRequired, "收信人称谓"));
            RuleFor(m => m.Subject).NotEmpty().WithMessage(string.Format(ValidatorRuleString.FieldRequired, "邮件主题(标题)"));
            RuleFor(m => m.Body).NotEmpty().WithMessage(string.Format(ValidatorRuleString.FieldRequired, "邮件内容"));
            RuleFor(m => m.CustomerId).Must(x => x > 0).WithMessage(ValidatorRuleString.RequireEmailBindtoAccountWhenSendEmail);
            SetDatabaseValidationRules<QueuedEmail>(dbContext);
        }
    }
}
